<?php

namespace App\Http\Controllers;

use Illuminate\Http\Request;
use DB;
use Hash;
use App\Http\Requests;
use App\Http\Controllers\Controller;

class LoginController extends Controller
{
	//登录首页
    public function getIndex(){
        //解析页面
        return view('login/login');

    } 

    //登录检测
    public function postCheck(Request $request){
    	$res = $request->only(['UserName','PassWord','_token']);
    	// dd($res);
    	//查询用户名是否存在
    	$name = DB::table('person')->where('UserName',$res['UserName'])->first();
		//检测密码是否正确
		if (Hash::check($res['PassWord'], $name['PassWord'])) {
			// echo '成功';
            session(['id'=>$name['id']]);
			session(['role'=>$name['Authority']]);
			session(['username'=>$name['PersonName']]);
            // $role = session('role');
            // dd($role);
            $notice = DB::table('notice')->get();

			return redirect('/Personnel/Person')->with('success','登陆成功');
		}else{
			return back()->with('error','用户名或密码错误');
			// echo '失败';
		}
    	
    	
    }
    //退出
    public function getExit(){
            session(['id'=>'']);
            session(['username'=>'']);

            return redirect('/login')->with('error','请登录');


    }


}
